<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
    <script language="JavaScript" src="/newmain/js/bizjs/gy.js"></script>
</head>
<body>
<form class="layui-form" method="post">
    <div class="layui-form-item" id="searchDiv">
        <div class="layui-input-inline">
            <input type="text" id="nsrsbh" class="layui-input" autocomplete="off" placeholder="请输纳税人识别号">
        </div>

        <div class="layui-input-inline">
            <input type="text" id="nsrmc" class="layui-input" autocomplete="off" placeholder="请输入企业名称">
        </div>

        <div class="layui-input-inline">
            <input type="text" id="ajbh" class="layui-input" autocomplete="off" placeholder="请输案件编号">
        </div>

        <div class="layui-input-inline">
            <input type="text" readonly class="layui-input" id="qlsj" placeholder="清理时间">
        </div>

        <div class="layui-input-inline" >
            <!--                <button class="layui-btn" onclick="search()" id="search">查询</button>-->
            <button type="button" class="layui-btn" lay-submit="" lay-filter="demo">查询</button>
        </div>
    </div>
</form>

<div id="showTable_div">
    <table class="layui-table" id="showTable" lay-filter="showTable" ></table>
</div>
<div class="panel panel-default operation_case_dataScope" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="uploadExcelYjqlsj">请选择需要导入的案件编号Excel</button>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-primary" id="btn_importTempDownload">导入模板下载</button>
                <!--                    <button  class="layui-btn"  id="submit_importByAjbh" lay-filter="submit_importByAjbh">保存</button>-->
                <button class="layui-btn layui-btn-primary" id="btn_cancel_imp">返回</button>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="batchEdit" >批量修改预计清理时间</button>
        <button class="layui-btn layui-btn-sm" lay-event="batchImport" >导入</button>
    </div>
</script>

</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var table = layui.table;
    var upload = layui.upload;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var startTime;
    var endTime;
    var importXafaId;
    layui.use(['table', 'layer', 'laydate','upload'], function () {
        //加载table
        tableIns1 = table.render({
            elem: '#showTable'
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , page: true //开启分页
            , url: '/jaajxxYjqlsj/listByPage' //数据接口
            , method: 'POST'
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'id', title: 'id',hide: true},
                    {field: 'jcajxxuuid', title: '金三案件信息表主键', width: 0,hide:true},
                    {field: 'ajbh', title: '案件编号',align : 'center'},
                    {field: 'nsrsbh', title: '纳税人识别号',align : 'center'},
                    {field: 'nsrmc', title: '纳税人名称',align : 'center'},
                    {field: 'yjqlTime', title: '预计清理时间',align : 'center'},
                    {field: 'yxbz', title: '是否有效',align : 'center'}
                ]
            ]
            , toolbar: '#toolbar'
        });
        laydate.render({
            elem: '#qlsj'
            , type: 'date'
            , range: '~'
            , done: function (value, date, endDate) {
                if (value != null && value != undefined && value != "") {
                    startTime = value.split("~")[0];
                    endTime = value.split("~")[1];
                } else {
                    startTime = null;
                    endTime = null;
                }

            }
        });
        // 监听工具栏事件
        table.on('toolbar(showTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'batchEdit':
                    // 批量编辑逻辑
                    var data = checkStatus.data;
                    if(data.length === 0){
                        layer.msg('请选择要编辑的数据');
                    }else{
                        layer.prompt({
                            formType: 2,
                            title: '预计清理时间(yyyy-MM-dd)',
                            area: ['200px', '50px']
                        }, function(value, index){
                            // 提交编辑的值
                            layer.close(index);
                            // 执行批量更新操作，更新选中行的 score 字段为 value
                            $.each(data, function(index, item){
                                item.yjqlTime = value; // 修改选中行的 score 值
                            });
                            console.log(data);
                            CoreUtil.sendPut("/jaajxxYjqlsj/plupdateyjqltime", data,function (res) {
                                layer.msg(res.msg);
                                tableIns1.reload({
                                    page: {
                                        curr: 1 //重新从第 1 页开始
                                    }
                                });
                            });
                        });
                    }
                    break;
                    case 'batchImport':
                        $(".operation_case_dataScope").show();
                        $("#searchDiv").hide();
                        $("#showTable_div").hide();
                        break;
            };
        });
        form.on('submit(demo)',function(data){
            var whereParams = {
                "nsrsbh":$("#nsrsbh").val(),
                "nsrmc":$("#nsrmc").val(),
                "ajbh":$("#ajbh").val(),
                "startTime":startTime,
                "endTime":endTime
            };
            tableIns1.reload({
                contentType: 'application/json'
                , headers: {"authorization": token}
                ,where :whereParams
                , url: '/jaajxxYjqlsj/listByPage' //数据接口
                , method: 'POST'
                , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                        "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                    }
                }, page: {
                    curr: 1 //重新从第 1 页开始
                }
            },false);
        })
        var uploadInst = upload.render({
            elem: '#uploadExcelYjqlsj'
            ,url:'/attention/jaajxxYjqlsj/importByajbhYjqlsj'
            ,data:{swjgDm: function(){
                    return $("#swjgDm").val();
                }}
            ,auto:true
            , headers: {"authorization": token}
            // ,bindAction:'#btn_importTempDownload',
            ,accept:'file'
            ,acceptMime:'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
            ,exts:'xls|xlsx'
            ,before:function(obj){
                layer.load(); //上传loading
            }
            ,done: function(res, index, upload){
                let data = res.data;
                console.log(data);
                let notexistsAjbhs = data.notexistsAjbhs
                if(notexistsAjbhs.length ==  0){
                    layer.alert("成功导入案件信息"+"【"+data.importCount+"】条!", function(){
                        // 点击确定按钮后执行的回调函数
                        // 刷新当前页面
                        location.reload();
                    });
                }else {
                    layer.alert("成功导入案件信息"+"【"+data.importCount+"】条!不在积案中的案件编号为："+notexistsAjbhs, function(){
                        location.reload();
                    });
                }
                layer.closeAll('loading'); //关闭loaWding
            }
            ,error: function(){
                layer.alert("导入案件失败，请重试！");
                layer.closeAll('loading'); //关闭loading
            }
        });

    });

    $("#btn_cancel_imp").click(function () {
        $(".operation_case_dataScope").hide();
        $("#searchDiv").show();
        $("#showTable_div").show();
        return false;
    });
    $("#btn_importTempDownload").click(function () {
        var a = document.createElement('a');
        a.setAttribute('href', 'http://72.1.9.104/files/jayjqlsjtmeplate.xlsx');
        a.setAttribute('target', '_blank');
        a.setAttribute('id', 'js_a');
        //防止反复添加
        if(document.getElementById('js_a')) {
            document.body.removeChild(document.getElementById('js_a'));
        }
        document.body.appendChild(a);
        a.click();
    });
    //执行查询
    function search() {
        //这里以搜索为例
        tableIns1.reload({
            where: { //设定异步数据接口的额外参数，任意设
                key: $("#key").val()
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    };
</script>